using System;
using System.Collections.Generic;
using System.Text;
using DTO;
using DAO;
using System.Data;

namespace BUS
{
    /// <summary> 
    ///Author: nnamthach@gmail.com 
    /// <summary>
    public class GadgetItemsControl
    {
        #region Local Variable
        private GadgetItemsDataAccess _objDAO;
        #endregion Local Variable

        #region Method
        public GadgetItemsControl()
        {
            _objDAO = new GadgetItemsDataAccess();
        }

        public GadgetItemsInfo Get(
        Int32 ID,
        ref string sErr)
        {
            return _objDAO.Get(
            ID,
            ref sErr);
        }

        public DataTable GetAll(
        ref string sErr)
        {
            return _objDAO.GetAll(
            ref sErr);
        }

        public Int32 Add(GadgetItemsInfo obj, ref string sErr)
        {
            return _objDAO.Add(obj, ref sErr);
        }

        public string Update(GadgetItemsInfo obj)
        {
            return _objDAO.Update(obj);
        }

        public string Delete(
        Int32 ID
        )
        {
            return _objDAO.Delete(
            ID
            );
        }
        public Boolean IsExist(
        Int32 ID
        )
        {
            return _objDAO.IsExist(
            ID
            );
        }

        public DataTableCollection Get_Page(GadgetItemsInfo obj, string orderBy, int pageIndex, int pageSize, ref String sErr)
        {
            return _objDAO.Get_Page(obj, orderBy, pageIndex, pageSize, ref sErr);
        }

        public DataTable Search(String columnName, String columnValue, String condition, ref String sErr)
        {
            return _objDAO.Search(columnName, columnValue, condition, "", ref  sErr);
        }
        public string InsertUpdate(GadgetItemsInfo obj)
        {
            string sErr = "";
            if (IsExist(
            obj.ID
            ))
            {
                sErr = Update(obj);
            }
            else
                Add(obj, ref sErr);
            return sErr;
        }

        public DataTable GetTransferOut(string dtb, object from, object to, ref string sErr)
        {
            return _objDAO.GetTransferOut(dtb, from, to, ref sErr);
        }

        public DataTable ToTransferInStruct()
        {
            GadgetItemsInfo inf = new GadgetItemsInfo();
            return inf.ToDataTable();
        }

        public string TransferIn(DataRow row)
        {
            GadgetItemsInfo inf = new GadgetItemsInfo(row);
            return InsertUpdate(inf);
        }
        #endregion Method

        public DataTable GetByType(string type, ref string sErr)
        {
            return _objDAO.GetByType(type, ref sErr);
        }
        public DataTable GetByGadget(string parent, string type, ref string sErr)
        {
            return _objDAO.GetByGadget(parent, type, ref sErr);
        }

        public DataTable GetParentName(string type, ref string sErr)
        {
            return _objDAO.GetParentName(type, ref sErr);
        }

        public DataTable GetNew(string type, ref string sErr)
        {
            return _objDAO.GetNew(type, ref sErr);
        }
    }
}
